Bug 5198

Bug Description:

This is a race.
Fields params and method in class org.codehaus.groovy.runtime.metaclass.MetaMethodIndex$CacheEntry are published unsfaely.
An exception will be thrown when run the given groovy test:

Exception in thread "Thread-3669" org.codehaus.groovy.runtime.InvokerInvocation Exception:
groovy.lang.MissingMethodException: No signature of method: static Foo.valueOf() is applicable for argument types: (java.lang.String) values: [bar] Possible solutions: valueOf(java.lang.String), valueOf(java.lang.Class, java.lan g.String), values()
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:97)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at groovy.lang.Closure.call(Closure.java:282)
at groovy.lang.Closure.call(Closure.java:277)
at groovy.lang.Closure.run(Closure.java:360)
at java.lang.Thread.run(Thread.java:724)
Caused by: groovy.lang.MissingMethodException: No signature of method: static Fo o.valueOf() is applicable for argument types:(java.lang.String) values: [bar] Possible solutions:valueOf(java.lang.String), valueOf(java.lang.Class, java.lan g.String), values()
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1357)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1343)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:767)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.asType(DefaultGroovyMethods.java:14464)
...
More details about this bug are at GROOVY-5198 JIRA page.

How To Reproduce:

This bug is reproduced under groovy 1.7.9 and JDK 1.6.0_33.
Execute the following scripts to run the test to reproduce the bug (assume the location of the groovy test project is groovy_test_home).

Linux:
${groovy_test_home}/scripts/run5198.sh [--threadnum arg] [--loops arg]
Windows:
%groovy_test_home%\scripts\run5198.bat [--threadnum arg] [--loops arg]

The default argument values will be taken if not specified. For example,
${groovy_test_home}/scripts/run5198.sh
is the same as
${groovy_test_home}/scripts/run5198.sh --threadnum 2000 --loops 100

Option Function Default Value Valid Values
--threadnum,-tn thread number 2000 integer
--loops, -l loop number 100 integer